package com.lgy.ms.core.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;


/**
 * @version V1.0
 * @Title: DateUtil.java
 * @Description:日期工具类
 * @Author: szwW Date 2013年11月21日
 */
public class DateUtil {
    public static final  String EXACT_TIME = "yyyy-MM-dd HH:mm:ss" ;
    public static final  String DAY_TIME = "yyyy-MM-dd" ;
    public static final  String DAY_FORMAT ="yyyyMMdd";
    /**
     * 获取当前包含毫秒时间字符串
     *
     * @return 当前时间字符串 yyyyMMddHHmmss
     * @Date:2013年12月5日
     * @author:zwsun
     */
    public static String getCurrentDateTime() {
        Date date = new Date();
        SimpleDateFormat sim = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String dateChar = sim.format(date);
        return dateChar;
    }

    public static Date str2Date(String str, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        try {
            Date date = format.parse(str);
            return date;
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String dateToStrLong(Date dateDate,String pattern) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        String dateString = formatter.format(dateDate);
        return dateString;
    }

    public static Date addDay(Date date,int day){
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        c.add(Calendar.DAY_OF_MONTH, day);
        Date newDate = c.getTime();
        return newDate;

    }

    //@时间：2018/8/1 15:33
    //@描述：根据时间格式获取当前时间
    public static String getCurrentDate4Pattern(String patten) {
        Date date = new Date();
        SimpleDateFormat sim = new SimpleDateFormat(patten);
        String dateChar = sim.format(date);
        return dateChar;
    }

    public static String formatDate(Date date, String pattern) {
        SimpleDateFormat format = new SimpleDateFormat(pattern);
        return format.format(date);
    }
}
